package com.qy127.controller;

import com.qy127.dao.StaffDao;
import com.qy127.entity.Staff;
import com.qy127.util.OSSUploadUtil;
import com.qy127.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/information")
public class informationController {

    @Autowired
    private StaffDao staffDao;
    /**
     * 上传图片
     * @param file
     * @return
     */
    @RequestMapping("/uploadFile")
    public Map uploadFile(MultipartFile file, HttpServletRequest request){
        String url = OSSUploadUtil.upload2(file);

        request.getSession().setAttribute("url",url);
        System.out.println(url+"777777777777777777777777777");
        HashMap<Object, Object> map = new HashMap<>();

        Staff staff = (Staff)request.getSession().getAttribute("staff");
        int i = staffDao.updateUrl(url, staff.getStaffId().toString());
        System.out.println(i+"66666666666666666");
        if (i>0){
            map.put("msg","上传成功");
        }else {
            map.put("msg","上传失败");
        }
        return map;
    }

    /*@RequestMapping("/queryinformation")
    @ResponseBody
    public Result queryOneStaff(HttpServletRequest request){
        Staff staff = (Staff)request.getSession().getAttribute("staff");
        List<Map> maps = staffDao.informationStaff(staff.getStaffId().toString(),staff.getPassword());
        Result result = new Result(maps.size(), maps);
        return result;
    }*/
}
